import { Timer } from 'babylon-lib/misc/timer';
import * as Data from '../../data/data';
import { CONTROLLER_TIP_MODE, CONTROLLER_TIP_TYPE, ControllerTip } from 'babylon-lib/xr/xr-input/controller-tip';
import { NotePanel } from '../../ui/note-panel';
import { SoundManager } from './sound-manager';


class ProgressManager {

    private static _initialized = false;
    private static _started = false;

    public static reset(): void {
        Timer.pause = true;
        this._started = false;

        SoundManager.reset();
        ControllerTip.disable();
    }

    public static start(): void {
        Timer.intervalInSeconds = 1;
        Timer.start();
        Timer.pause = false;
        if (!this._initialized) {
            this.initialize();
            this._initialized = true;
        }
        this._started = true;
    }

    public static set pause(pause: boolean) {
        Timer.pause = pause;
    }

    public static get started(): boolean {
        return this._started;
    }

    private static initialize(): void {
        const _this = ProgressManager;

        Timer.addIntervalHandle(() => {
            if (!Timer.pause) Data.gameTime.value++;
        });

        Timer.addDurationHandle(0, () => {
            SoundManager.background.play();
            Data.controlPanelDisplay.value = true;
            Data.gameOn.value = true;
        });

        Timer.addDurationHandle(2, () => {
            ControllerTip.enable(CONTROLLER_TIP_MODE.SHORT, CONTROLLER_TIP_TYPE.TRIGGER);
            NotePanel.note(20, '🔊\t搜寻并引导炮火摧毁敌方火力点。');
            SoundManager.noteStart.play();
        });
    }

}


export { ProgressManager };